const { ccclass, property } = cc._decorator;
import loadLobby from '../Load/loadLobby';
import detailsManager from './DetailsManager';
import ScrollSelect from './ScrollSelect';
import levelChoiceControl from './levelChoiceControl';

@ccclass
export default class initLobby extends cc.Component {
    @property(cc.Node)
    bgNode: cc.Node = null;
    @property(cc.Node)
    heroNode: cc.Node = null;
    @property(cc.Node)
    detailsNode: cc.Node = null;
    @property(cc.Node)
    levelChoice: cc.Node = null;

    _loadLobby: loadLobby = null;
    onLoad() {
        //gameHelper.getInstance().clearLocal();

        //获取常驻节点所绑定的脚本 
        let lobbyNode = cc.director.getScene().getChildByName('loadLobby');
        if (lobbyNode) {
            this._loadLobby = lobbyNode.getComponent(loadLobby);
            this.bgNode.getComponent(cc.Sprite).spriteFrame = this._loadLobby._LobbyBg;
            gameHelper.getInstance().gameJson = this._loadLobby._gameJson;
            gameHelper.getInstance().levelLength = this._loadLobby._gameJson.Level.length;
            if (gameHelper.getInstance().levelParam.length > 0)
                gameHelper.getInstance().selectLevelId = gameHelper.getInstance().levelParam.length;
            this.levelChoice.getComponent(levelChoiceControl)._itemPrefab = this._loadLobby._levelItemPfb;
            let dm = this.detailsNode.getComponent(detailsManager);
            dm._heroDetails = this._loadLobby._heroDetails;
            dm._heroIcons = this._loadLobby._heroIcons;
            dm.setHeroScrol();
        }
    }
}
